package com.itcodai.config.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author c-fanqj
 * @date 2023/3/23
 * @apiNote Swagger2配置
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig /*implements WebMvcConfigurer*/ {

    /*@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }*/


    /**
     * 添加摘要信息(Docket)
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                //.groupName("carInfo")
                // 指定构建api文档的详细信息的方法：apiInfo()
                .apiInfo(apiInfo())
                //是否开启 (true 开启  false隐藏。生产环境建议隐藏)
                //.enable(false)
                .select()
                // 指定要生成api接口的包路径，这里把controller作为包路径，生成controller中的所有接口
                .apis(RequestHandlerSelectors.basePackage("com.itcodai.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 构建api文档的详细信息
     * @return ApiInfo
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 设置页面标题(API名称)
                .title("Spring Boot集成Swagger2接口规范")
                // 设置接口描述
                .description("跟武哥一起学Spring Boot")
                // 设置联系方式
                .contact("倪升武，" + "CSDN：http://blog.csdn.net/eson_15")
                // 设置版本
                .version("1.0")
                // 构建
                .build();

                /*.title("Client Gateway-Swagger2 APIs")
                .termsOfServiceUrl("https://blog.csdn.net/lovequanquqn?viewmode=list")
                .contact(new Contact("unnet","https://blog.csdn.net/lovequanquqn?viewmode=list","love1208tt@foxmail.com"))
                .version("1.0.0")
                .build();*/
    }

}
